package com.atguigu.mapreduce.demo.comparable;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * @version V1.0
 * @author: guangcheng
 * @date: 2021/11/20 22:03
 * @description:
 */
public class MyPartitioner extends Partitioner<FlowBean, Text> {


    /**
     * 从map输出的每一个<K,V>都会进来, 进行分区标记, 去往该去的分区
     *
     * @param flowBean
     * @param text
     * @param numPartitions
     * @return
     */
    @Override
    public int getPartition(FlowBean flowBean, Text text, int numPartitions) {

        String phone = text.toString();

        int partition = 0;
        if (phone.startsWith("136")) {
            partition = 0;
        } else if (phone.startsWith("137")) {
            partition = 1;
        } else if (phone.startsWith("138")) {
            partition = 2;
        } else if (phone.startsWith("139")) {
            partition = 3;
        } else {
            partition = 4;
        }

        return partition;
    }

}

